<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学生id" prop="stuId">
        <el-input
          v-model="queryParams.stuId"
          placeholder="请输入学生id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户口所在地地址" prop="stuResidenceAddress">
        <el-input
          v-model="queryParams.stuResidenceAddress"
          placeholder="请输入户口所在地地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学习工作单位" prop="stuWorkingCompany">
        <el-input
          v-model="queryParams.stuWorkingCompany"
          placeholder="请输入学习工作单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="简历" prop="stuResume">
        <el-input
          v-model="queryParams.stuResume"
          placeholder="请输入简历"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="奖励处分" prop="stuReward">
        <el-input
          v-model="queryParams.stuReward"
          placeholder="请输入奖励处分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家庭成员" prop="stuHomemembers">
        <el-input
          v-model="queryParams.stuHomemembers"
          placeholder="请输入家庭成员"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="通讯地址" prop="stuMailAddress">
        <el-input
          v-model="queryParams.stuMailAddress"
          placeholder="请输入通讯地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="移动电话" prop="stuMobile">
        <el-input
          v-model="queryParams.stuMobile"
          placeholder="请输入移动电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="stuEmail">
        <el-input
          v-model="queryParams.stuEmail"
          placeholder="请输入邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业单位" prop="stuUgSchool">
        <el-input
          v-model="queryParams.stuUgSchool"
          placeholder="请输入毕业单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业专业" prop="stuUgMajor">
        <el-input
          v-model="queryParams.stuUgMajor"
          placeholder="请输入毕业专业"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="毕业年月" prop="stuUgTime">
        <el-input
          v-model="queryParams.stuUgTime"
          placeholder="请输入毕业年月"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="一志愿报考学校" prop="stuPgFirstWishSchool">
        <el-input
          v-model="queryParams.stuPgFirstWishSchool"
          placeholder="请输入一志愿报考学校"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="一志愿报考专业" prop="stuPgFirstWishMajor">
        <el-input
          v-model="queryParams.stuPgFirstWishMajor"
          placeholder="请输入一志愿报考专业"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="一志愿报考专业方向" prop="stuPgFirstWishDirection">
        <el-input
          v-model="queryParams.stuPgFirstWishDirection"
          placeholder="请输入一志愿报考专业方向"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="外国语" prop="stuPgExamForeignScore">
        <el-input
          v-model="queryParams.stuPgExamForeignScore"
          placeholder="请输入外国语"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="政治理论" prop="stuPgExamPolitical">
        <el-input
          v-model="queryParams.stuPgExamPolitical"
          placeholder="请输入政治理论"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数学" prop="stuPgExamMath">
        <el-input
          v-model="queryParams.stuPgExamMath"
          placeholder="请输入数学"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="自命题" prop="stuPgExamSchool">
        <el-input
          v-model="queryParams.stuPgExamSchool"
          placeholder="请输入自命题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="初试总分" prop="stuPgExamTotal">
        <el-input
          v-model="queryParams.stuPgExamTotal"
          placeholder="请输入初试总分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="复试成绩" prop="stuPgReview">
        <el-input
          v-model="queryParams.stuPgReview"
          placeholder="请输入复试成绩"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="总成绩" prop="stuPgTotal">
        <el-input
          v-model="queryParams.stuPgTotal"
          placeholder="请输入总成绩"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="调剂专业" prop="stuPgSecondMajor">
        <el-input
          v-model="queryParams.stuPgSecondMajor"
          placeholder="请输入调剂专业"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="调剂专业方向" prop="stuPgSecondDirection">
        <el-input
          v-model="queryParams.stuPgSecondDirection"
          placeholder="请输入调剂专业方向"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考生来源类别" prop="stuSourceType">
        <el-select v-model="queryParams.stuSourceType" placeholder="请选择考生来源类别" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="学生支撑材料，成绩单，创新创业，发表论文等" prop="stuDependence">
        <el-input
          v-model="queryParams.stuDependence"
          placeholder="请输入学生支撑材料，成绩单，创新创业，发表论文等"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="stuComment">
        <el-input
          v-model="queryParams.stuComment"
          placeholder="请输入备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新时间" prop="updateDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.updateDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['mentor:detail:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['mentor:detail:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['mentor:detail:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['mentor:detail:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" v-if="false"/>
      <el-table-column label="学生id" align="center" prop="stuId" />
      <el-table-column label="户口所在地地址" align="center" prop="stuResidenceAddress" />
      <el-table-column label="学习工作单位" align="center" prop="stuWorkingCompany" />
      <el-table-column label="简历" align="center" prop="stuResume" />
      <el-table-column label="奖励处分" align="center" prop="stuReward" />
      <el-table-column label="家庭成员" align="center" prop="stuHomemembers" />
      <el-table-column label="通讯地址" align="center" prop="stuMailAddress" />
      <el-table-column label="移动电话" align="center" prop="stuMobile" />
      <el-table-column label="邮箱" align="center" prop="stuEmail" />
      <el-table-column label="毕业单位" align="center" prop="stuUgSchool" />
      <el-table-column label="毕业专业" align="center" prop="stuUgMajor" />
      <el-table-column label="毕业年月" align="center" prop="stuUgTime" />
      <el-table-column label="一志愿报考学校" align="center" prop="stuPgFirstWishSchool" />
      <el-table-column label="一志愿报考专业" align="center" prop="stuPgFirstWishMajor" />
      <el-table-column label="一志愿报考专业方向" align="center" prop="stuPgFirstWishDirection" />
      <el-table-column label="外国语" align="center" prop="stuPgExamForeignScore" />
      <el-table-column label="政治理论" align="center" prop="stuPgExamPolitical" />
      <el-table-column label="数学" align="center" prop="stuPgExamMath" />
      <el-table-column label="自命题" align="center" prop="stuPgExamSchool" />
      <el-table-column label="初试总分" align="center" prop="stuPgExamTotal" />
      <el-table-column label="复试成绩" align="center" prop="stuPgReview" />
      <el-table-column label="总成绩" align="center" prop="stuPgTotal" />
      <el-table-column label="调剂专业" align="center" prop="stuPgSecondMajor" />
      <el-table-column label="调剂专业方向" align="center" prop="stuPgSecondDirection" />
      <el-table-column label="考生来源类别" align="center" prop="stuSourceType" />
      <el-table-column label="学生支撑材料，成绩单，创新创业，发表论文等" align="center" prop="stuDependence" />
      <el-table-column label="备注" align="center" prop="stuComment" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['mentor:detail:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['mentor:detail:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改研究生详细信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学生id" prop="stuId">
          <el-input v-model="form.stuId" placeholder="请输入学生id" />
        </el-form-item>
        <el-form-item label="户口所在地地址" prop="stuResidenceAddress">
          <el-input v-model="form.stuResidenceAddress" placeholder="请输入户口所在地地址" />
        </el-form-item>
        <el-form-item label="学习工作单位" prop="stuWorkingCompany">
          <el-input v-model="form.stuWorkingCompany" placeholder="请输入学习工作单位" />
        </el-form-item>
        <el-form-item label="简历" prop="stuResume">
          <el-input v-model="form.stuResume" placeholder="请输入简历" />
        </el-form-item>
        <el-form-item label="奖励处分" prop="stuReward">
          <el-input v-model="form.stuReward" placeholder="请输入奖励处分" />
        </el-form-item>
        <el-form-item label="家庭成员" prop="stuHomemembers">
          <el-input v-model="form.stuHomemembers" placeholder="请输入家庭成员" />
        </el-form-item>
        <el-form-item label="通讯地址" prop="stuMailAddress">
          <el-input v-model="form.stuMailAddress" placeholder="请输入通讯地址" />
        </el-form-item>
        <el-form-item label="移动电话" prop="stuMobile">
          <el-input v-model="form.stuMobile" placeholder="请输入移动电话" />
        </el-form-item>
        <el-form-item label="邮箱" prop="stuEmail">
          <el-input v-model="form.stuEmail" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="毕业单位" prop="stuUgSchool">
          <el-input v-model="form.stuUgSchool" placeholder="请输入毕业单位" />
        </el-form-item>
        <el-form-item label="毕业专业" prop="stuUgMajor">
          <el-input v-model="form.stuUgMajor" placeholder="请输入毕业专业" />
        </el-form-item>
        <el-form-item label="毕业年月" prop="stuUgTime">
          <el-input v-model="form.stuUgTime" placeholder="请输入毕业年月" />
        </el-form-item>
        <el-form-item label="一志愿报考学校" prop="stuPgFirstWishSchool">
          <el-input v-model="form.stuPgFirstWishSchool" placeholder="请输入一志愿报考学校" />
        </el-form-item>
        <el-form-item label="一志愿报考专业" prop="stuPgFirstWishMajor">
          <el-input v-model="form.stuPgFirstWishMajor" placeholder="请输入一志愿报考专业" />
        </el-form-item>
        <el-form-item label="一志愿报考专业方向" prop="stuPgFirstWishDirection">
          <el-input v-model="form.stuPgFirstWishDirection" placeholder="请输入一志愿报考专业方向" />
        </el-form-item>
        <el-form-item label="外国语" prop="stuPgExamForeignScore">
          <el-input v-model="form.stuPgExamForeignScore" placeholder="请输入外国语" />
        </el-form-item>
        <el-form-item label="政治理论" prop="stuPgExamPolitical">
          <el-input v-model="form.stuPgExamPolitical" placeholder="请输入政治理论" />
        </el-form-item>
        <el-form-item label="数学" prop="stuPgExamMath">
          <el-input v-model="form.stuPgExamMath" placeholder="请输入数学" />
        </el-form-item>
        <el-form-item label="自命题" prop="stuPgExamSchool">
          <el-input v-model="form.stuPgExamSchool" placeholder="请输入自命题" />
        </el-form-item>
        <el-form-item label="初试总分" prop="stuPgExamTotal">
          <el-input v-model="form.stuPgExamTotal" placeholder="请输入初试总分" />
        </el-form-item>
        <el-form-item label="复试成绩" prop="stuPgReview">
          <el-input v-model="form.stuPgReview" placeholder="请输入复试成绩" />
        </el-form-item>
        <el-form-item label="总成绩" prop="stuPgTotal">
          <el-input v-model="form.stuPgTotal" placeholder="请输入总成绩" />
        </el-form-item>
        <el-form-item label="调剂专业" prop="stuPgSecondMajor">
          <el-input v-model="form.stuPgSecondMajor" placeholder="请输入调剂专业" />
        </el-form-item>
        <el-form-item label="调剂专业方向" prop="stuPgSecondDirection">
          <el-input v-model="form.stuPgSecondDirection" placeholder="请输入调剂专业方向" />
        </el-form-item>
        <el-form-item label="考生来源类别" prop="stuSourceType">
          <el-select v-model="form.stuSourceType" placeholder="请选择考生来源类别">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="学生支撑材料，成绩单，创新创业，发表论文等" prop="stuDependence">
          <el-input v-model="form.stuDependence" placeholder="请输入学生支撑材料，成绩单，创新创业，发表论文等" />
        </el-form-item>
        <el-form-item label="备注" prop="stuComment">
          <el-input v-model="form.stuComment" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable size="small"
            v-model="form.createDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新时间" prop="updateDate">
          <el-date-picker clearable size="small"
            v-model="form.updateDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="删除标记" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标记" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDetail, getDetail, delDetail, addDetail, updateDetail, exportDetail } from "@/api/mentor/detail";

export default {
  name: "Detail",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 研究生详细信息表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuId: undefined,
        stuResidenceAddress: undefined,
        stuWorkingCompany: undefined,
        stuResume: undefined,
        stuReward: undefined,
        stuHomemembers: undefined,
        stuMailAddress: undefined,
        stuMobile: undefined,
        stuEmail: undefined,
        stuUgSchool: undefined,
        stuUgMajor: undefined,
        stuUgTime: undefined,
        stuPgFirstWishSchool: undefined,
        stuPgFirstWishMajor: undefined,
        stuPgFirstWishDirection: undefined,
        stuPgExamForeignScore: undefined,
        stuPgExamPolitical: undefined,
        stuPgExamMath: undefined,
        stuPgExamSchool: undefined,
        stuPgExamTotal: undefined,
        stuPgReview: undefined,
        stuPgTotal: undefined,
        stuPgSecondMajor: undefined,
        stuPgSecondDirection: undefined,
        stuSourceType: undefined,
        stuDependence: undefined,
        stuComment: undefined,
        createDate: undefined,
        updateDate: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        delFlag: [
          { required: true, message: "删除标记不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询研究生详细信息列表 */
    getList() {
      this.loading = true;
      listDetail(this.queryParams).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        stuId: undefined,
        stuResidenceAddress: undefined,
        stuWorkingCompany: undefined,
        stuResume: undefined,
        stuReward: undefined,
        stuHomemembers: undefined,
        stuMailAddress: undefined,
        stuMobile: undefined,
        stuEmail: undefined,
        stuUgSchool: undefined,
        stuUgMajor: undefined,
        stuUgTime: undefined,
        stuPgFirstWishSchool: undefined,
        stuPgFirstWishMajor: undefined,
        stuPgFirstWishDirection: undefined,
        stuPgExamForeignScore: undefined,
        stuPgExamPolitical: undefined,
        stuPgExamMath: undefined,
        stuPgExamSchool: undefined,
        stuPgExamTotal: undefined,
        stuPgReview: undefined,
        stuPgTotal: undefined,
        stuPgSecondMajor: undefined,
        stuPgSecondDirection: undefined,
        stuSourceType: undefined,
        stuDependence: undefined,
        stuComment: undefined,
        createDate: undefined,
        updateDate: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加研究生详细信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改研究生详细信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDetail(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDetail(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除研究生详细信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDetail(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有研究生详细信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDetail(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
